#include "SoundManager.h"
#include <iostream>
SoundManager::SoundManager()
{	
	
    if (!_sounds[jump].loadFromFile("sound/saut.wav"))
		std::cerr << "Error : Unable to load the file saut.wav \n";
	
	if (!_sounds[collect].loadFromFile("sound/piece.wav"))
		std::cerr << "Error : Unable to load the file piece.wav \n";
	
	if (!_sounds[fall].loadFromFile("sound/monde-termine.wav"))
		std::cerr << "Error : Unable to load the file monde-termine.wav \n";

	if (!_sounds[ghost_die].loadFromFile("sound/ghost-die.wav"))
		std::cerr << "Error : Unable to load the file ghost-die.wav \n";

	if (!_sounds[ghost_laugh].loadFromFile("sound/ghost-laugh.wav"))
		std::cerr << "Error : Unable to load the file ghost-laugh.wav \n";

	if (!_sounds[damage].loadFromFile("sound/ahou.wav"))
		std::cerr << "Error : Unable to load the file ahou.wav \n";

	if (!_sounds[next_level].loadFromFile("sound/tuyau.wav"))
		std::cerr << "Error : Unable to load the file tuyau.wav \n";

	if (!_sounds[death].loadFromFile("sound/death.wav"))
		std::cerr << "Error : Unable to load the file death.wav \n";

	if (!_sounds[up].loadFromFile("sound/up.wav"))
		std::cerr << "Error : Unable to load the file up.wav \n";

}

SoundManager::~SoundManager(){}


void SoundManager::playSound(SoundType st)
{
	cleanSounds();
	sf::Sound s;
	s.setBuffer(_sounds[st]);
	_soundCollection.push(s);
	_soundCollection.back().play();

}

void SoundManager::cleanSounds()
{
	while(!_soundCollection.empty() && !(_soundCollection.front().getStatus()==sf::Sound::Playing))
	{
		_soundCollection.pop();
	}
}